local MiddleOpenDB = require("middle.MiddleOpenDB")
local ServerCommon = require("serverCommon.ServerCommonFW")
local MiddleLogic = require("middle.MiddleLogic")
local DailyActConfig = require("excel.Activity").dailyAct
local ActRuleConfig = require("excel.Activity").dailyActRule
local Lang = require("common.Lang")
local DailyActFW = require("activity.DailyActFW")
local CopyCommon = require("copy.CopyCommon")
local Config = require("Config")

function checkOpenMiddle(actID)
  if Config.IS_MIDDLE then
      return 1
  end
  local config = DailyActConfig[actID]
  if config == nil then
      return 0
  end
  if config.middle == 0 then
      return 0
  end
  if not MiddleOpenDB.isMiddleOpen() then
      return 0
  end
  if not MiddleLogic.ENABLE_MIDDLE then
      return 0
  end
  local openDay = ServerCommon.getHadOpenDay()
  if config.middleDay + 1 > openDay then
      return 0
  end
  if _G.msg_middle_parse.check_connect() ~= true then
        return
  end
  return 1
end

function checkCanEnterMiddle(human, actID, copyID) --跨服活动
  local conf = DailyActConfig[actID]
  if conf == nil then
      return ""
  end
 
  local actRuleID = DailyActFW.onGetRunningActRuleID(actID) 
  if actRuleID == nil then
      return Lang.MIDDLE_ACT_NO_OPEN
  end
  local rule = ActRuleConfig[actRuleID]
  if not rule then
      return Lang.MIDDLE_ACT_NO_OPEN
  end
  local copy = rule.args[7]
  if copy ~= copyID then
      return Lang.MIDDLE_ACT_NO_OPEN_MIDDLE
  end
  
  local err = CopyCommon.checkEnterCondition(human, copyID)
  if err then
      return err
  end
end
